﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PlantsVsZombies
{
    public class Zombie : Ghost
    {
        public Zombie(ContentManager content, Vector2 pos, int timeAppear)
        {
            this.Visible = false;
            this.AppearTime = timeAppear;
            this.DeltaMove = 2f;
            this.Blood = 10;
            this.GhostStatus = GhostStatus.Move;
            this.Sprites = new List<Sprite>();
            Size = new Vector2(83,90);
            Position = pos;

            int nMove = 6;
            String[] textureMove = new string[nMove];
            for (int i = 0; i < nMove; i++)
                textureMove[i] = @"Image\Ghost\zombie\ZombieMove_" + i.ToString("00");
            Sprite tempMove = new Sprite(content, textureMove, nMove, pos, Size);
           // tempMove.Visible = true;

            int nAttack = 3;
            String[] textureAttack = new string[nAttack];
            for (int i = 0; i < nAttack; i++)
                textureAttack[i] = @"Image\Ghost\zombie\ZombieAttack_" + (i+1).ToString("00");
            Sprite tempAttack = new Sprite(content, textureAttack, nAttack, pos, Size);
            //tempAttack.Visible = false;

            this.NSprites = 2;
            this.Sprites.Add(tempMove);
            this.Sprites.Add(tempAttack);
        }
        public override void Update(GameTime gameTime)
        {
            if(Visible)
                if(GhostStatus == GhostStatus.Move)
                {
                    Vector2 location = Position;
                    location.X -= DeltaMove;
                    Position = location;
                }
                    //foreach (Sprite t in Sprites)
                    //{
                    //    Vector2 location = t.Position;
                    //    location.X -= DeltaMove;
                    //    t.Position = location;
                    //}

            base.Update(gameTime);
        }
        public override void Draw(SpriteBatch spriteBatch)
        {
            //base.Draw(spriteBatch);
            
            switch(GhostStatus)
            {
               case GhostStatus.Move:
                    {
                        Sprites[0].Position = Position;
                        Sprites[0].Draw(spriteBatch);
                        break;
                    }
              case GhostStatus.Attack:
                    {
                        Sprites[1].Position = Position;
                        Sprites[1].Draw(spriteBatch);
                        break;
                    }
               case GhostStatus.Die:
                    {
                        this.Visible = false;
                        break;
                    }
            }
        }

        public override void EatPlant(Plant plant)
        {
            if(IsCollisionPlant(plant))
            {
                if (plant.Blood >= 0)
                {
                    plant.Blood -= 1f;
                }
                else
                {
                    plant.Visible = false;
                    plant.Position = new Vector2(-100,-100);//thoat ra ngoai man hinh
                    GhostStatus = GhostStatus.Move;
                }
            }
        }
     
    }
}
